using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using InfraStructureLayer;
using WebControls;
using System.Collections.Generic;
using BusinessLayer;
using System.Drawing;

public partial class UserControls_uctCalendar : SFUserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["SelectedDate"] == null)
            {
                Calendar1.SelectedDate = DateTime.Now;
                Session["SelectedDate"] = Calendar1.SelectedDate;
            }
            else
            {
                Calendar1.SelectedDate = Convert.ToDateTime(Session["SelectedDate"]);
                Calendar1.VisibleDate = Convert.ToDateTime(Session["SelectedDate"]);
            }
            SetDate();

        }
    }

    public void SetDate()
    {
        lblMonthAndYear.Text = StaticMethods.GetErrorMessageMultilanguageString(30 + Calendar1.SelectedDate.Month, new object[] { }) + " " + Calendar1.SelectedDate.Year.ToString();
    }
    
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        
            Session["SelectedDate"] = Calendar1.SelectedDate;
            Response.Redirect("~/" + CurrentContext.Language + "/default.aspx?Year=" + Calendar1.SelectedDate.Year.ToString() + "&Month=" + Calendar1.SelectedDate.Month.ToString() + "&Day=" + Calendar1.SelectedDate.Day.ToString());
        
    }
    
    protected void lbtNextMonth_Click(object sender, EventArgs e)
    {
    
        Calendar1.SelectedDate = Calendar1.SelectedDate.AddMonths(1);
        Calendar1.VisibleDate = Calendar1.SelectedDate;
        lblMonthAndYear.Text = StaticMethods.GetErrorMessageMultilanguageString(30 + Calendar1.SelectedDate.Month, new object[] { }) + " " + Calendar1.SelectedDate.Year.ToString();
        Session["SelectedDate"] = Calendar1.SelectedDate;
    }
    protected void lblPrevMonth_Click(object sender, EventArgs e)
    {
    
        Calendar1.SelectedDate = Calendar1.SelectedDate.AddMonths(-1);
        Calendar1.VisibleDate = Calendar1.SelectedDate;
        lblMonthAndYear.Text = StaticMethods.GetErrorMessageMultilanguageString(30 + Calendar1.SelectedDate.Month, new object[] { }) + " " + Calendar1.SelectedDate.Year.ToString();
        Session["SelectedDate"] = Calendar1.SelectedDate;
    }
    List<DateTime> dateTimes = null;
    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
        if(dateTimes==null)
        {
            busCalendar insBusCalendar = new busCalendar();
            DataTable insDataTableCalendar = insBusCalendar.SelectDatesThatContainsContent();
            dateTimes = new List<DateTime>();
            foreach(DataRow dr in insDataTableCalendar.Rows)
            {
                if(!dateTimes.Contains( Convert.ToDateTime(dr["InsertDate"])))
                {
                dateTimes.Add(Convert.ToDateTime(dr["InsertDate"]));
                }
            }
        }
        if (dateTimes.Contains(e.Day.Date))
        {
            e.Cell.ForeColor = Color.FromArgb(255,132,0);
        }
    }
}
